package cn.hxlc.tie.demo.modular.ljt.equipment.controller;


import cn.hxlc.tie.demo.modular.ljt.equipment.entity.EquipmentCategory;
import cn.hxlc.tie.demo.modular.ljt.equipment.model.params.EquipmentGroupParam;

import cn.hxlc.tie.demo.modular.ljt.equipment.model.result.EquipmentGroupResult;
import cn.hxlc.tie.demo.modular.ljt.equipment.service.EquipmentCategoryService_lt;
import cn.hxlc.tie.libs.scanner.annotation.GetResource;
import cn.hxlc.tie.libs.scanner.annotation.PostResource;
import cn.hxlc.tie.libs.scanner.stereotype.ApiResource;
import cn.hxlc.tie.model.page.PageResult;
import cn.hxlc.tie.model.web.response.ResponseData;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lt
 * @Data 2021-07-09
 */
@RestController
@ApiResource(name = "分组",path = "/equipmentCategory")
public class EquipmentCategoryController_lt {

    @Autowired
    private EquipmentCategoryService_lt equipmentCategoryService;

    /**
     * 分组分页查询列表
     * @param param
     * @return
     */
    @GetResource(name = "分页列表", path = "/queryListPage", requiredPermission = false)
    @ApiOperation(value = "分页查询列表",response = EquipmentGroupResult.class)
    public ResponseData queryListPage(EquipmentGroupParam param) {
        PageResult<EquipmentGroupResult> pageBySpec = equipmentCategoryService.findPageBySpec(param);
        return ResponseData.success(pageBySpec);
    }

    /**
     * 分组查看单条详情
     * @param eid
     * @return
     */
    @GetResource(name = "查询详情", path = "/queryDetail", requiredPermission = false)
    @ApiOperation(value = "查询详情",response = EquipmentGroupResult.class)
    public ResponseData queryDetail(@RequestParam Long eid) {
        EquipmentCategory detail = equipmentCategoryService.detail(eid);
        return ResponseData.success(detail);
    }

    /**
     *  分组 编辑
     * @param param
     * @return
     */
    @PostResource(name = "编辑", path = "/update")
    @ApiOperation("编辑")
    public ResponseData Update(@RequestBody EquipmentGroupParam param) {
        equipmentCategoryService.updateEquipmentCategory(param);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE, "编辑成功", null);
    }

    /**
     *  分组 删除
     */
    @GetResource(name = "删除", path = "/delete")
    @ApiOperation("删除")
    public ResponseData Delete(Long id) {
        equipmentCategoryService.deleteById(id);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE, "删除成功", null);
    }

    @PostResource(name = "新增", path = "/add")
    @ApiOperation("新增")
    public ResponseData Add(@RequestBody EquipmentGroupParam param) {
        equipmentCategoryService.addEquipmentCategory(param);
        return ResponseData.success(ResponseData.DEFAULT_ERROR_CODE, "新增成功", null);
    }

}
